% $Header: /cvsrepos/html2ps/postscript/vertical-align.ps,v 1.1 2008/07/01 12:33:12 sergey Exp $

/vertical-align-text-top {
} def

/vertical-align-text-bottom {
  1 index get-line-baseline neg
  1 index get-baseline            % => Parent Child MaxBaseline Baseline

  2 copy ge {
    pop 
    1 index put-baseline
  } {
    sub 
    2 index get-line
    { 
      dup get-baseline
      2 index sub
      exch put-baseline 
    } forall
    2 index get-line-baseline
    add
    2 index put-line-baseline     % => Parent Child
  } ifelse 
} def

/vertical-align-super {
  dup get-baseline 2 div
  1 index put-baseline
} def

/vertical-align-sub {
  1 index get-line-baseline neg
  1 index get-baseline
  2 div
  add
  1 index put-baseline
} def
/vertical-align-top {
} def
/vertical-align-middle {
  vertical-align-baseline

  dup get-default-baseline
  1 index get-baseline
  sub 2 div 

  1 index get-baseline
  add  
  1 index put-baseline
} def

% TODO:
/vertical-align-bottom {
  1 index get-line-baseline neg
  1 index get-baseline            % => Parent Child MaxBaseline Baseline

  2 copy ge {
    pop 
    1 index put-baseline
  } {
    sub 
    2 index get-line
    { 
      dup get-baseline
      2 index sub
      exch put-baseline 
    } forall
    2 index get-line-baseline
    add
    2 index put-line-baseline     % => Parent Child
  } ifelse 
} def
/vertical-align-baseline {         % => Parent Child
  1 index get-line-baseline neg
  1 index get-baseline             % => Parent Child MaxBaseline Baseline

  2 copy ge {
    pop 
    1 index put-baseline
  } {
    sub 
    2 index get-line
    { 
      dup get-baseline
      2 index sub
      exch put-baseline 
    } forall
    2 index get-line-baseline
    add
    2 index put-line-baseline     % => Parent Child
  } ifelse 
} def
